package com.example.property.mapper;

import com.example.property.pojo.Building;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BuildingMapper {
    @Select("<script>select building_id,building_name from" +
            " building " +
            "<where>" +
            "<if test='status != 0'>" +
            "building_status = #{status}</if>" +
            "</where>" +
            "</script>")
    List<Building> buildingsOfStatus(@Param("status") int status);
    @Update("<script>update building set building_status =" +
            "#{status} where building_id in " +
            "<foreach open='(' close=')' collection='idList' item='i' separator=','>" +
            "#{i}" +
            "</foreach>" +
            "</script>")
    int changeBuildingStatus(@Param("idList") List<Integer> idList,
    @Param("status") Integer status);
    @Insert("INSERT INTO building  VALUES" +
            " (#{building_id}, #{building_name}, #{building_code}, #{building_status}, #{building_floors}, #{completed_date}, #{design_life}, #{ownership})")
    int insertBuilding(Building building);


    @Insert("<script>" +
            "insert into building " +
            "(building_id, building_code, building_name, building_status, building_floors, completed_date, design_life, ownership) values " +
            "<foreach collection=\"list\" index=\"i\" item=\"item\" separator=\",\">" +
            "( #{item.building_id}, #{item.building_code}," +
            " #{item.building_name}, #{item.building_status}, " +
            "#{item.building_floors}, #{item.completed_date}, " +
            "#{item.design_life}, #{item.ownership} ) " +
            "</foreach>" +
            "</script>")
    @Options(useGeneratedKeys = true, keyProperty = "building_id", keyColumn = "building_id")

    int insertBuildings(List<Building> buildings);









}
